package me.xiaosiqi.server_info.tool;


import cn.hutool.json.JSONUtil;
import me.xiaosiqi.server_info.comm.system.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: xiaosiqi
 * @Description:
 * @date 2021/11/12 16:31
 */
@Component
public class ServerDescTool {

    private static String port;
    @Value("${server.port}")
    public void setPort(String port) {
        ServerDescTool.port = port;
    }

    public static String getNetInfo(List<String> ipList){
        StringBuilder desc =new StringBuilder();
        for (String ip : ipList) {
            if (ip.contains(":")){
                String url = "服务器后台地址 [http://[%%]:port](http://[%%]:port)\n\n".replace("%%", ip).replace("port",port);
                desc.append(url);
            }else {
                String url = "服务器后台地址 [http://[%%]:port](http://[%%]:port)\n\n".replace("[%%]", ip).replace("port",port);;
                desc.append(url);
            }
        }
        return desc.toString();
    }


    public static String getServerInfo() throws Exception {
        Server server = new Server();
        server.serverInfo();
        String s = JSONUtil.toJsonStr(server);
        System.out.println(s);
        return  s;
    }
}
